//
//  DQPublishViewController.m
//  DQBaisibudejie
//
//  Created by 杜倩 on 16/8/29.
//  Copyright © 2016年 杜倩. All rights reserved.
//

#import "DQPublishViewController.h"
#import "DQButton.h"//调用自定义的--修改内部布局
@interface DQPublishViewController ()

@property(nonatomic,strong)NSArray *imgs;//保存图片
@property(nonatomic,strong)NSArray *titles;//保存标题

@end

@implementation DQPublishViewController

- (void)viewDidLoad {
    [super viewDidLoad];
 //添加图片
    UIImageView *imgView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"app_slogan"]];//定义UIImageView的时候直接添加图片，UIImageView大小就和UIImage图片的大小一样
    //设置位置---设置x,y
    imgView.center=CGPointMake(UIScreenw/2, UIScreenh/5);

    //加载在图片
    _imgs=@[@"publish-audio",@"publish-offline",@"publish-picture",@"publish-review",@"publish-text",@"publish-video"];
    _titles=@[@"发视频",@"发图片",@"发段子",@"发声音",@"发帖子",@"发链接"];
    
    //添加
    [self.view addSubview:imgView];
    [self addButton];
}
#pragma mark 添加屏幕上的六个按钮
-(void)addButton{
    //每行多少列
    int column=3;
    //距离顶端的距离
    CGFloat top = UIScreenh *0.5;
    //设置左右间距
    CGFloat margin = 5;
    //中间的间距
    CGFloat margin1=15;
    //设置每行的宽
    CGFloat buttonW=(UIScreenw - 2 * margin - (column-1) *margin1)/3.0;
    //高度
    CGFloat buttonH=buttonW;
    
    //使用九宫格添加
    for (int i=0; i<self.imgs.count; i++) {
       // NSLog(@"23");
        //调用的
        DQButton *button=[DQButton buttonWithType:UIButtonTypeCustom];
        //设置图片的标题
        [button setTitle:self.titles[i] forState:UIControlStateNormal];
        //图片
        [button setImage:[UIImage imageNamed: self.imgs[i]] forState:UIControlStateNormal];
        //设置x,y轴
        CGFloat x = i % column;
        CGFloat y = i/column;
        
        button.frame = CGRectMake(margin+x*(buttonW+margin1), top+(buttonH+margin1)*y, buttonW, buttonH);//x轴：左边的间距+（行宽+中间的间距）*x    y轴：
        //单击事件
        [button addTarget:self action:@selector(Click:) forControlEvents:UIControlEventTouchUpInside];
        
        //设置体字颜色
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        [self.view addSubview:button];
    }
}

#pragma mark 按钮的单击事件---多个按钮监听一个方法，最好有一个参数
-(void)Click:(UIButton *)sender{
    NSLog(@"12345");
}



-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self dismissViewControllerAnimated:YES completion:nil];//随处点，退出发表控制器
}

#pragma mark 返回按钮
- (IBAction)backController:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

@end
